目標:做出首頁 Hero、導覽列、作品卡片、頁尾;串接留言 API(或先以假資料渲染)。
WorkCard
接受 title, cover, tags, link
alt
文字、按鈕 aria-label
假資料(client/data/works.json
)
[
{ "title": "醫療儀表板", "cover": "/img/work1.png", "tags": ["React","Chart"], "link": "#" },
{ "title": "RWD 個人頁", "cover": "/img/work2.png", "tags": ["HTML","CSS"], "link": "#" }
]
前端 fetch 串接(精簡版)
async function loadComments(){
const res = await fetch('https://你的後端網域/api/comments');
return await res.json();
}
async function sendComment(name, message){
const res = await fetch('https://你的後端網域/api/comments',{
method:'POST', headers:{'Content-Type':'application/json'},
body: JSON.stringify({ name, message })
});
return await res.json();
}
檢查清單
GET /api/works
回傳硬編碼陣列。works.json
移到 server/db/works.json
,改由 GET /api/works
讀檔回傳。works
表,欄位 { id, title, cover, tags (JSON), link }
,前端以 fetch('/api/works')
取得並渲染。